package algorithm.beforestart.primary.str;

import java.util.HashMap;

public class firstUniqChar {

    public static int firstUniqChar(String s) {
        HashMap<String,Integer> map =new HashMap<String,Integer>();
        for(int i=0;i<s.length();i++){
            String key =s.substring(i,i+1);
            if(map.containsKey(key)){
                Integer count =map.get(key);
                map.put(key,count+1);
            }else{
                map.put(key,1);
            }

        }

        for(int i=0;i<s.length();i++){
            Integer count =map.get(s.substring(i,i+1));
            if(count==1){
                return i;
            }
        }

        return -1;

    }

    public static void main(String[] args) {
        System.out.println(firstUniqChar("loveleetcode"));
    }
}
